package com.kailong.servlet.student;

import com.kailong.dao.ManageAdviceDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/student/doStudentAdvice")
public class DoStudentAdvice extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        HttpSession session = req.getSession();
        String sno = (String) session.getAttribute("sno");
        String name = (String) session.getAttribute("sname");
        String sclass = (String) session.getAttribute("sclass");
        String title = req.getParameter("title");
        String content = req.getParameter("content");
        PrintWriter out1 = resp.getWriter();
//        out1.println(sno);
//        out1.println(name);
//        out1.println(sclass);
//        out1.println(title);
//        out1.println(content);
        int count = 0;
        count = ManageAdviceDao.insertAdvice(sno,name,sclass,title,content);
        PrintWriter out = resp.getWriter();
        if (count>0){
            out.print("<script>");
            out.print("alert('提交成功');window.location.href='studentAdvice.jsp'");
            out.print("</script>");
        }else {
            out.print("<script>");
            out.print("alert('提交失败！');window.location.href='studentAdvice.jsp'");
            out.print("</script>");
        }

    }
}
